{"id":1744,"date":"2021-01-29T08:34:37","date_gmt":"2021-01-29T08:34:37","guid":{"rendered":"https:\/\/www.miquido.com\/blog\/?p=1744"},"modified":"2023-11-13T13:04:37","modified_gmt":"2023-11-13T12:04:37","slug":"is-kotlin-multiplatform-the-future","status":"publish","type":"post","link":"https:\/\/www.miquido.com\/blog\/is-kotlin-multiplatform-the-future\/","title":{"rendered":"Is Kotlin Multiplatform the future of cross-platform development? Tips on how to get started"},"content":{"rendered":"\n
Nowadays, we can observe a trend in custom mobile app development<\/a> to release apps faster. There were many attempts to reduce the time of development by sharing common code parts among different platforms such as Android and iOS. Some solutions have already gained popularity, while others are still under development. Today, I\u2019d like to discuss one of the newest approaches from the second group – Kotlin Multiplatform Mobile (KMM for short).<\/strong><\/p>\n\n\n\n KMM is an SDK that primarily aims to share business logic among platforms <\/strong>– the part that in most cases has to be the same anyway. This is achieved thanks to a set of multiple compilers for a shared module. For example, Android target uses a Kotlin\/JVM variant, and for iOS there is a Kotlin\/Native one. A shared module can be then added to typical native app projects and developers responsible for UI can focus on delivering the best experience for users in an environment familiar to them – Android Studio for Android and Xcode for iOS. <\/p>\n\n\n\n Currently, one of the most popular cross-platform solutions is Flutter app development<\/a>. It is focused on the \u201cwrite one app and run it everywhere\u201d rule \u2013 which works, but only for simple apps. In real case scenarios, developers often have to write native code for each platform anyway to fill the gaps<\/strong>, for example, when some plugin is missing. With this approach, the app looks the same on different platforms, which sometimes is desirable, but in some cases, it can break specific design guidelines.<\/p>\n\n\n\n While they may sound similar, Kotlin Multiplatform is not a cross-platform solution – it doesn\u2019t try to reinvent the wheel. Developers can still use tools they know and like. It just simplifies the process of reusing parts of code <\/strong>that previously should have been written multiple times, like making network requests, storing data and other business logic.<\/p>\n\n\n\n When dealing with projects sporting substantial existing codebases or libraries, Kotlin steps into the spotlight as a pivotal advantage. Here, developers can strategically introduce Kotlin Multiplatform modules, embarking on a gradual migration journey. This approach ensures a seamless transition, preserving the investments in well-established codebases while leveraging Kotlin’s interoperability. Kotlin Multiplatform is particularly well-suited for large-scale enterprise applications where maintaining consistency and reusability across platforms is paramount.<\/p>\n\n\n\n Flutter excels in crafting visually appealing and consistent user interfaces with its Dart programming language. It creates a unified UI experience using its rendering engine and Dart language. The framework provides a comprehensive set of pre-built widgets, ensuring consistency in appearance and behaviour across different platforms. On the other hand, Kotlin Multiplatform focuses on maximizing code reuse and minimizing platform-specific implementations. <\/p>\n\n\n\n In essence, while Kotlin Multiplatform and Flutter contribute significantly to the cross-platform development landscape, the decision-making process involves a thoughtful evaluation of project requisites and team capabilities. Kotlin Multiplatform’s strengths shine brightly in scenarios where enterprise-level consistency, codebase adaptability, and strategic migration approaches take precedence. At the same time, Flutter excels in projects where a seamless and visually consistent user interface across platforms is a primary concern. <\/p>\n\n\n\n Pros of KMM<\/strong>:<\/p>\n\n\n\n Cons of KMM<\/strong>:<\/p>\n\n\n\n According to the official site<\/a>, companies are increasingly gaining interest in this technology and the list is continuously getting longer and longer. Among them, there are such well-known brands like Autodesk, VMWare, Netflix or Yandex.<\/p>\n\n\n\n The best place to dive for in-depth information is the official guide<\/a>, but in this article, I would like to show an example that is fairly simple, but more interesting than just a \u201cHello World\u201d, which would be app fetching and displaying the latest comic<\/a> by Randall Munroe (licensed under CC BY-NC 2.5<\/a>) with its title from xkcd.com API<\/a>. <\/p>\n\n\n\n Features to be covered:<\/p>\n\n\n\n Note: I wanted this sample to be as easy to read for both Android and iOS developers, so in some places I intentionally omitted some platform-specific good practises just to make it clear what is going on \ud83d\ude42<\/p>\n\n\n\n First, make sure you have the latest versions of Android Studio and Xcode<\/strong> installed because both of them will be necessary for the build of this project. Then, in Android Studio, install the KMM plugin<\/a>. This plugin simplifies a lot of things – to create a new project, just click Create New Project and select KMM Application.What is Kotlin Multiplatform Mobile?<\/h2>\n\n\n\n
Kotlin Multiplatform vs Flutter<\/h2>\n\n\n\n
When to choose Kotlin Multiplatform over Flutter?<\/h3>\n\n\n\n
Pros and cons of Kotlin Multiplatform<\/h2>\n\n\n\n
\n
\n
Which companies use KMM?<\/h2>\n\n\n\n
How to get started with Kotlin Multiplatform?<\/h2>\n\n\n\n
\n
Project setup<\/h3>\n\n\n\n
<\/p>\n\n\n\n